package chapter4;
import java.util.Scanner;
/****************************************************************
 * Author：icynlau
 * Description: 美元美分这样的货币单位问题
 * 				通过字符串处理代替数据类型转换，解决后者可能出现的精度丢失问题（float->int）
 * 				类似的思路也可以用于进行大数运算， 比如大数加减法
 * Date:2021/4/2
 * ***************************************************************
 */
public class exc4_26 {
	public static void main(String[] args) {
		Scanner input=new Scanner(System.in);
		System.out.println("Enter the money amount  (eg:11.56) :");
		String s=input.next();
		int index=s.indexOf('.');
		String dollars=s.substring(0,index);
		String pennies=s.substring(index+1);
//		System.out.println(dollars+"\n"+pennies);
		
		int numberofDollars=Integer.parseInt(dollars);
		
		int nPennies=Integer.parseInt(pennies);
		int numberofQuarters=nPennies/25;
		nPennies=nPennies%25;
		
		int numberofDimes=nPennies/10;
		nPennies=nPennies%10;
		
		int numberofNickels=nPennies/5;
		nPennies=nPennies%5;
		
		int numberofPennies=nPennies;
		
		System.out.println("you have "+numberofDollars +" Dollars ;");
		System.out.println("you have "+numberofQuarters +" Quarters ;");
		System.out.println("you have "+numberofDimes +" Dimes ;");
		System.out.println("you have "+numberofNickels +" Nickels ;");
		System.out.println("you have "+numberofPennies +" Pennies ;");
		
		
		
	}

}
